<?php

namespace App\Models\V1;

use Illuminate\Database\Eloquent\Factories\HasFactory;

class Vote extends BaseModel
{
    use HasFactory;
    protected $table="vote";

    protected $fillable=['id','title','content','vote_class_id','preparatory_id','end_time','thumb','voter_turnout','n_vote','a_vote','state'];

    /**
     * 状态
     * @param $key
     * @return string
     */
    public function getStateAttribute($key)
    {
        return (string) $key;
    }

    public function VoteClass()
    {
        return $this->hasOne(VoteClass::class, 'id', 'vote_class_id');
    }


    public function Preparatory()
    {
//        return $this->hasOne(Preparatory::class, 'id', 'preparatory_id');
        return $this->hasOne(Preparatory::class, 'id', 'preparatory_id')->select('id','nickname','community_name','community_id');
    }

}
